import {Component, OnInit} from '@angular/core';
import {HttpClient} from "@angular/common/http";


@Component({
  selector: 'app-userm',
  templateUrl: './userm.component.html',
  styleUrls: ['./userm.component.css']
})
export class UsermComponent implements OnInit {
  constructor(private tokenService: HttpClient) {
  }

  date;
  users;
  user;
  edi = false;

  ngOnInit() {
    laydate.render({
      elem: '#birthday',
      format: 'dd/MM/yyyy'
    });
    this.getPage();
  }

  getPage() {

    this.tokenService.get('http://193.112.113.194:8769/store/users/0/3').subscribe(data => {
      this.users = data['retval']['content'];
    })
  }

  edit(uid: string) {

    this.tokenService.get('http://193.112.113.194:8769/store/users/' + uid).subscribe(data => {
      this.user = data['retval'];
    });
    this.edi = true;
  }

  del(uid: string) {
    this.tokenService.delete('http://127.0.0.1:8769/store/users/' + uid).subscribe(data => {

    }, () => {

    }, () => {
      this.getPage();
    });
  }

  submitEdit() {
    this.tokenService.post('http://127.0.0.1:8769/store/users', this.user).subscribe(data => {

    }, () => {

    }, () => {
      this.getPage();
    });
  }

}
